<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>报价计算</title>
</head>
<body style="margin:0 auto;width:800px">
  <div style="margin-top:10px">
	 默认重量为：20.5<br/><hr/>
     请输入邮编<textarea rows="5" cols="100" id="origin-data"></textarea><br/>
     查询结果<br/><textarea rows="5" cols="100" id="new-data"></textarea><br/><br/>
     提示:<span id="info"></span><hr/>
     <button style="width:200px;height:50px;font-size:20px;margin-left:300px;cursor:pointer" onclick="changeData()">查询运输方式</button>
     </div>
  </div>
  <script type="text/javascript">
    function changeData(){
    //美西
    var america_west = {
      '2':['90000-90899','91000-91899','92200-92899'],
      '3':['85400-85499','86400-86499','88900-89299','93600-93999','94300-94399','95000-95399'],
      '4':['84000-85399','85500-86399','86500-86599','87300-87499','89300-89899','94000-94299','94400-94999','95400-96199','97500-97699'],
      '5':['59000-59199','59400-59499','59600-59999','67700-67799','67900-67999','69300-69399','73900-73999','79000-79199','79300-79499','79700-83899','87000-87299','87500-88599','97000-97499','97700-98699','98800-99499'],
      '6':['50500-50599','50800-50899','51000-51699','56100-56199','57000-58199','58300-58899','59200-59399','59500-59599','64000-64999','65600-67699','67800-67899','68000-69299','71000-71199','71800-71899','72600-72799','72900-73899','74000-77599','77800-78999','79200-79299','79500-79699'],
      '7':['35000-35899','36500-36799','36900-37299','37500-37599','38000-38499','38600-39799','42000-42499','46000-46699','46900-46999','47400-47999','49800-50499','50600-50799','50900-50999','52000-56099','56200-56799','58200-58299','60000-63999','65000-65599','70000-70999','71200-71799','71900-72599','72800-72899','77600-77799'],
      '8':['00400-00500','01000-08900','10000-33900','34100-34199','34200-34999','35900-36499','36800-36899','37300-37499','37600-37999','38500-38599','39800-39899','39900-41899','42500-45999','46700-46899','47000-47399','48000-49799']
    };
    
    //美东
    var america_east = {
      '2':['004-005','010-013','015-018','020-024','027-029','034-034','052-053','055','060-089','100-127','137-139','170-172','175-176','178-199','219-219'],
      '3':['014-014','019-019','025-026','030-033','035-043','045-045','050-051','054-054','056-059','128-136','140-142','144-149','155-155','157-159','163-163','166-169','173-174','177-177','200-218','220-238','254-254','267-267'],
      '4':['044-044','046-049','143-143','150-154','156-156','160-162','164-165','239-253','255-266','268-288','293-293','295-297','376-376','403-406','410-418','430-459','467-468','470-470','473-473','480-489','492-492'],
      '5':['289-292','294-394','298-324','326-329','335-336','338-338','342-347','350-364','367-375','377-386','388-389','393-393','397-402','407-409','420-427','460-466','469-469','471-472','474-479','490-491','493-499','504-504','506-507','520-539','541-549','556-559','600-639','650-652','654-655','723-724'],
      '6':['325-325','330-334','337-337','339-339','341-341','349-349','365-366','387-387','390-392','394-396','500-503','505-505','508-516','540-540','550-555','560-576','580-585','640-649','653-653','656-676','680-689','691-692','700-722','725-732','734-738','740-762','764-764','773-773','776-777'],
      '7':['577-577','586-593','677-679','690-670','693-693','733-733','739-739','763-763','765-772','774-775','778-797','800-812','814-814','816-820','822-828','875-877','881-884'],
      '8':['594-599','798-799','813-813','815-815','821-821','829-874','878-880','885-961','970-986','988-994']
       };
      //美西报价
      var america_west_price = {
        '2':88.2,
        '3':107.0,
        '4':122.3,
        '5':144.5,
        '6':179.7,
        '7':209.4,
        '8':232.5
      };
      //美东报价
      var america_east_price = {
        '2':87.1,
        '3':106.9,
        '4':120.1,
        '5':143.5,
        '6':176.3,
        '7':206.9,
        '8':229.3
      };

      //计算
      var  postcode = document.getElementById("origin-data").value;  //邮编
      
      var  west_price = 0; //定义区间
      var  east_price = 0; //定义区间

      var  west_section = '';
      var  east_section = '';

      if(postcode == "" ){
        document.getElementById("new-data").value ="";
        alert("请输入邮编");
      }else{
      	  //美西区计算
	      for(var section_key in america_west){
	      	for(var i = 0 ; i < america_west[section_key].length; i++){
	      		var temp = america_west[section_key][i]+"";
	      	    var tempPostCodeArr = temp.split('-');
		        var temp0 = tempPostCodeArr[0]+"";
		        var temp1 = tempPostCodeArr[1]+"";
		        if( parseInt(postcode) >= parseInt(temp0) && parseInt(postcode) <= parseInt(temp1)){
		          west_section = section_key;
		          west_price = america_west_price[section_key];
		          break;
		        }
	      	}
	      	if(west_price > 0 ){
	      		break;
	      	}
	      }
	      //美东区计算
	      for(var section_key in america_east){
	      	for(var j = 0 ; j < america_east[section_key].length; j++){
	      		var temp = america_east[section_key][j]+"";
		        var tempPostCodeArr = temp.split('-');
		        var temp0 = tempPostCodeArr[0]+'00';
		        var temp1 = tempPostCodeArr[1]+'00';
		        if( parseInt(postcode) >= parseInt(temp0) && parseInt(postcode) <= parseInt(temp1)){

		          east_section = section_key;
		          east_price = america_east_price[section_key];
		          break;
		        }
	        }
	        if(east_price > 0 ){
	      		break;
	      	}
	      }

	      if(west_price==0){
	        document.getElementById("new-data").value ="美东运输方式";
	      }
	      else if(east_price==0){
	      	document.getElementById("new-data").value ="美西运输方式";
	      }else{
	      	if(west_price<east_price){
	         document.getElementById("new-data").value ="美西运输方式";
		    }else{
		     document.getElementById("new-data").value ="美东运输方式";
		    }
	      }

	      
	      document.getElementById("info").innerHTML = "<br>美西<font style='color:red'>"+west_section+"</font>区报价为<font style='color:red'>"+west_price+"</font><br/>"+"美东<font style='color:red'>"+east_section+"</font>区报价为<font style='color:red'>"+east_price+"</font>";
      }
   }
      

  </script>
</body>
</html>